package tgc.edu.ljc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tgc.edu.ljc.custom.CommonService;
import tgc.edu.ljc.entity.Dept;
import tgc.edu.ljc.repository.DeptRepository;
@Service
public class DeptService extends CommonService<Dept, Integer>{
	@Autowired
	private DeptRepository deptDAO;
	
	public List<Dept> findByParentIsNull() {
		return deptDAO.findByParentIsNull();
	}

	public List<Dept> findByParentId(Integer id) {
		
		return deptDAO.findByParentId(id);
	}

	public void rename(Integer id, String name, Integer pId) {
		Dept model;
		if(id>10000) {
			model=new Dept();
			model.setParent(findById(pId));
		}else {
			model= findById(id);
		}
		model.setName(name);
		save(model);
	}

	public Dept add(Integer pId) {
		Dept model=new Dept();
		model.setName("新部门");
		model.setParent(findById(pId));
		save(model);
		return model;
	}

}
